package com.howtoplay.Handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

public class WebsocketTextHandler  extends TextWebSocketHandler {
    private static final Logger log = LoggerFactory.getLogger(WebsocketBinaryHandler.class);

    //建立连接
    @Override
    public void afterConnectionEstablished(WebSocketSession session) throws Exception {
        System.out.println(session.getAttributes().get("collector"));
        super.afterConnectionEstablished(session);
    }

    //接收到消息
    @Override
    protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
        System.out.println(message.getPayload());
        session.sendMessage(new TextMessage("reply.........."+message.getPayload()));
        super.handleTextMessage(session, message);
    }
}